package com.an;

public class HomeWork_2 {
    public static void main(String[] args) {
        B.register("李白","123526","10086@qq.com");

    }
}

/**要求
 用户名 密码 邮箱
 用户名长度为2,3,4
 密码长度为6 必须全为数字
 邮箱中包含@ 和. 且@在.之前

 */
class B{
    public static void register(String name,String password,String mailbox ){
        if(Isname(name)&&Ispassword(password)&&Ismailbox(mailbox)){
            System.out.println("注册成功");
            System.out.println("注册信息为");
            System.out.println("姓名:"+name+"\n"+ "密码:"+password+"\n"+"邮箱:"+mailbox);
        }
        else{
            System.out.println("注册失败");
        }

    }

    public  static boolean Isname(String name){
        if(name.length()>=2&&name.length()<=4){
            return true;
        }
        else{
            throw new RuntimeException("用户名长度为2,3,4");
        }
    }
    //密码
    public static boolean Ispassword(String password){
        int length=password.length();
        if(length!=6){
            throw new RuntimeException("密码长度不为6");
        }
        try {
            int num=Integer.parseInt(password);
        } catch (NumberFormatException e) {
            throw new RuntimeException("密码必须全为数字");
        }
        return true;
    }
    //邮箱
    public static boolean Ismailbox(String mailbox){
        int at=mailbox.indexOf("@");
        int point=mailbox.indexOf(".");
        if(at>=0&&point>at){
            return true;
        }
        else {
            throw new RuntimeException("邮箱中包含@ 和. 且@在.之前");
        }
    }
}
